<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
</head>
<body>
<script>
    /*
        原型
     */
    function MyClass1() {

    }

    function MyClass2() {

    }

    //所有对象共有的对象
    console.log(MyClass1.prototype)
    console.log(MyClass2.prototype)
    console.log(MyClass1.prototype === MyClass2.prototype)

    var mc1 = new MyClass1()
    console.log(mc1.__proto__)
    console.log(MyClass1.prototype === mc1.__proto__)

    MyClass1.prototype.a = 123
    mc1.a = "我是——火车王"
    console.log(mc1)
    //先找自己有没有，再找原型对象
    console.log(mc1.a)
    var mc2 = new MyClass1()
    console.log(mc2.a)

    MyClass1.prototype.sayHello = function () {
        console.log("hello world")
    }
    mc1.sayHello()

    //构造方法再改进
    function Person(name, age, gender) {
        this.name = name
        this.age = age
        this.gender = gender
    }

    Person.prototype.sayName = function () {
        console.log(this.name)
    }
    var p1 = new Person("吴死妈", 1, "人妖")
    p1.sayName()

    //使用in 检查某个对象中是否有某个属性
    function TheShy() {

    }

    var ts = new TheShy()
    TheShy.prototype.name = "炫神"
    console.log("name" in ts)
    //使用hasOwnProperty 检查某个对象自身是否真的有某个属性
    console.log(ts.hasOwnProperty("name"))

    console.log(ts.__proto__.hasOwnProperty("hasOwnProperty"))
    //原型也有原型
    console.log(ts.__proto__.__proto__.hasOwnProperty("hasOwnProperty"))
    //原型的原型就没有原型了
    console.log(ts.__proto__.__proto__.__proto__)

    /*
    数组
     */
    //字面量创建数组
    var arr01 = []
    console.log(arr01)
    //对象：内建对象、宿主对象、自定义对象
    //数组本质是内建对象
    console.log(typeof arr01)

    //数组可以放【任意】数据类型
    var arr02 = ["hello", 1, true, null, undefined]
    console.log(arr02.length)
    var obj01 = {name: "sima"}
    arr02[arr02.length] = obj01
    console.log(arr02)
    var arr03 = [{name: "司马薇"}, {name: "司马宏"}, {name: "司马兵"}]
    console.log(arr03)
    //函数也是对象也可以放进数组里面
    var arr04 = [
        function a() {
            console.log("雨薇死妈！")
        },
        function () {
            console.log("确实！")
        }
    ]
    console.log(arr04)
    arr04[0]()
    arr04[1]()
    //二维数组
    var arr05 = [[1, 2, 3], [1, 2, 3], [1, 2, 3]]
    console.log(arr05)

    //foreach
    var arr06 = ["周神", "世界", "第一", "牛逼"]
    arr06.forEach(function () {
        console.log("牛子")
    })

    //盘点10大数组删除删除元素的方法
    const arr07 = ['尼哥', '死', '妈']
    arr07.pop()
    console.log(arr07)
</script>
</body>
</html>
